﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FWMS.DAO
{
    class Rukuguanli_dateselect
    {
        //原料，物料条件查询
        public object[,] rukuguanli_dateSelect(string startdate, string enddate, string style, string pinming, string guige)
        {
            DB.DBbase dbbase = new DB.DBbase();
            string sql = "";
            if (!"".Equals(pinming))
            {
                if ("".Equals(guige))
                {
                    sql = "select yuanliaoruku_pinming,ruku_guige,ruku_yanshou,ruku_jianshu,ruku_zhongliang ,ruku_beizhu from rukuguanli where ruku_type = '" + style.ToString() + "' and                                ruku_yanshou between '" + startdate.ToString() + "' and '" + enddate.ToString() + "' and yuanliaoruku_pinming = '" + pinming + "' and (ruku_guige = '' or ruku_guige                            is null)";
                }
                else
                {
                    sql = "select yuanliaoruku_pinming,ruku_guige,ruku_yanshou,ruku_jianshu,ruku_zhongliang ,ruku_beizhu from rukuguanli where ruku_type = '" + style.ToString() + "' and                                ruku_yanshou between '" + startdate.ToString() + "' and '" + enddate.ToString() + "' and yuanliaoruku_pinming = '" + pinming + "' and ruku_guige = '" + guige + "'";
                }

            }
            else
            {
                sql = "select ruku_no,yuanliaoruku_pinming,ruku_guige,ruku_daohuo,ruku_yanshou,ruku_fahuodanwei from rukuguanli where ruku_type = '" + style.ToString() +                         "' and ruku_yanshou between '" + startdate.ToString() + "' and '" + enddate.ToString() + "'";
            }
            if (dbbase.ExecuteSQL(sql.Trim()))
            {
                if (dbbase.rows.Length != 0)
                {
                    return dbbase.rows;
                }
                else
                {
                    return null;
                }
            }
            else
            {
                return null;
            }
        }
        //产品条件查询
        public object[,] rukuguanli_chanpindateSelect(string startdate, string enddate, string style, string pinming, string guige)
        {
            DB.DBbase dbbase = new DB.DBbase();
            string sql = "";

            if (!"".Equals(pinming))
            {
                if ("".Equals(guige))
                {
                    sql = "select yuanliaoruku_pinming,ruku_guige,ruku_yanshou,ruku_jianshu,ruku_zhongliang ,ruku_beizhu from rukuguanli where (ruku_type = '3' or ruku_type='4') and                                     ruku_yanshou between '" + startdate.ToString() + "' and '" + enddate.ToString() + "'and yuanliaoruku_pinming = '" + pinming + "' and (ruku_guige ='' or ruku_guige                             is null)";
                }
                else
                {
                    sql = "select yuanliaoruku_pinming,ruku_guige,ruku_yanshou,ruku_jianshu,ruku_zhongliang ,ruku_beizhu from rukuguanli where (ruku_type = '3' or ruku_type='4') and                                     ruku_yanshou between '" + startdate.ToString() + "' and '" + enddate.ToString() + "'and yuanliaoruku_pinming = '" + pinming + "' and ruku_guige = '" + guige + "'";
                }
            }
            else
            {
                sql = "select ruku_yanshou,yuanliaoruku_pinming,ruku_guige,ruku_daohuo from rukuguanli where (ruku_type = '3' or ruku_type='4')  and ruku_yanshou between                       '" + startdate.ToString() + "' and '" + enddate.ToString() + "'";
            }

            if (dbbase.ExecuteSQL(sql.Trim()))
            {
                if (dbbase.rows.Length != 0)
                {
                    return dbbase.rows;
                }
                else
                {
                    return null;
                }
            }
            else
            {
                return null;
            }
        }
        //产品集记查询
        public object[,] rukuguanli_chanpindatejijiSelect(string startdate, string enddate)
        {
            DB.DBbase dbbase = new DB.DBbase();
            string sql = "select yuanliaoruku_pinming,ruku_guige,ruku_danwei,ruku_beizhu,sum(ruku_jianshu),sum(ruku_zhongliang) as zhongliang from rukuguanli where (ruku_type='3' or ruku_type='4') and ruku_yanshou between '" +
            startdate.ToString() + "' and '" + enddate.ToString() + "' group by yuanliaoruku_pinming,ruku_guige,ruku_danwei,ruku_beizhu";
            if (dbbase.ExecuteSQL(sql.Trim()))
            {
                if (dbbase.rows.Length != 0)
                {
                    return dbbase.rows;
                }
                else
                {
                    return null;
                }
            }
            else
            {
                return null;
            }
        }
    }
}
